# !/usr/bin/python3
# -*- coding: utf-8 -*-
"""
功能描述
----------------------------------------------------
@Project :   xinhou-openai-framework
@File    :   main.py
@Contact :   sp_hrz@qq.com

@Modify Time      @Author    @Version    @Desciption
------------      -------    --------    -----------
2023/2/10 14:19   shenpeng   1.0         None
"""

import uvicorn

from xinhou_openai_framework.core.beans.BeansContext import BeansContext
from xinhou_openai_framework.core.context.model.AppContext import AppContext
from xinhou_openai_framework.core.context.model.SystemContext import ctx
from xinhou_openai_framework.core.db.DatabaseManager import DatabaseManager
from xinhou_openai_framework.core.init.AppManager import AppManager

app = AppManager.create_app()

DatabaseManager.get_instance()

# 示例路由，使用 TraceID
# @app.get("/")
# async def read_root(request: Request):
#     trace_id = request.state.trace_id  # 获取 TraceID
#     return {"Trace-ID": trace_id}

if __name__ == '__main__':
    context: AppContext = ctx.__getattr__("context")  # 全局变量
    uvicorn.run(
        app="main:app",
        reload=False,
        host=context.application.server.host,
        port=context.application.server.post,
        loop="asyncio",  # 使用 asyncio 异步框架
        proxy_headers=True  # 启用代理头支持
    )

